// pages/login/login.js
import {http} from "../../utils/http"
Page({
  data: {
    show:false,
    username: "",
    password: "",
    loginFormRules: {
      mobile: [{
          required: true,
          message: "手机号码不能为空"
        },
        {
          pattern: /^1[3-9]\d{9}$/,
          message: "手机号码格式不正确"
        },
      ],
      pwd: [{
          required: true,
          message: "密码不能为空"
        },
        {
          pattern: /^\w{6,16}$/,
          message: "密码必须在6~16位之间"
        },
      ],
    },
  },
  show(){
    this.data.show =! this.data.show
    this.setData({
      show:this.data.show
    })
  },
  async goLogin() {
    if (this.data.username=="" || this.data.password=="") {
      wx.showToast({
        title: '请输入',
        icon:"error"
      })
    } else {
      let {data: res} = await http({
        url: "/user/m/login?deviceId=007&deviceName=monkey",
        method: "POST",
        data: {
          mobile: this.data.username,
          pwd: this.data.password
        },
        header: {
          "content-type": "application/x-www-form-urlencoded"
        }
      }).catch((err) => err)
      // console.log(res, 'login');
      let token = res.data.token
      wx.setStorageSync('token', token)
      if (res.code == 0) {
        wx.reLaunch({
          url: '/pages/home/home',
        })
      }
    }
  },
});